Translating Algorithm

Translating algorithm to Python Code

How to implement?
We will use a website called https://repl.it to implement algorithms

Example-1

Drawing a square in Python - turtle Size of each side = 100 dots
  • Move pen forward by 100 dots
  • Change the angle to the left by 90 degrees
  • Move pen forward by 100 dots
  • Change the angle to the left by 90 degrees
  • Move pen forward by 100 dots
  • Change the angle to the left by 90 degrees
  • Move pen forward by 100 dots
  • Change the angle to the left by 5 degrees
  •          Python code
             1. import turtle as t
             2. t.forward(100)
             3. t.left(90)
             4. t.forward(100)
             5. t.left(90)
             6. t.forward(100)
             7. t.left(90)
             8. t.forward(100)
             9. t.left(5)
         

    Repetition

             import turtle as t
             for i in range(4):
                t.forward(100)
                t.left(90)
         

    Repetition using: for counter in range(start, end): [list of instructions]

    This loop, repeats [list of instructions] from counter = start until end - 1
             import turtle as t
             for i in range(1,5):
                t.forward(100)
                t.left(90)
         

    Some turtle commands

    Drawing a circle

    Example of drawing a circle

             import turtle as t
             t.circle(50) 
             t.circle(50,180) 
             t.circle(50,180,4) 
         

    fillcolor ( colorName )

    1. t.fillcolor("red")
    2. t.begin_fill()
    3. t.circle( 50)
    4. t.end_fill()
    For more details, please contact me here.
    Date of last modification: 2021